package cn.zwx.learn.basic.redis_listener;

import cn.zwx.learn.basic.redis_listener.config.KeyUpdateEventMessageListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Component;

/**
 * @description: 感知Key过期业务回调
 * @projectName:java-basic
 * @see:cn.zwx.learn.basic.redis_listener
 * @author:zhangwenxue
 * @createTime:2021/5/10 13:43
 * @version:1.0
 */
@Component
public class RedisKeyUpdateListener extends KeyUpdateEventMessageListener {

    private final Logger logger = LoggerFactory.getLogger(RedisKeyExpirationListener.class);

    public RedisKeyUpdateListener(RedisMessageListenerContainer listenerContainer) {
        super(listenerContainer);
    }

    @Override
    public void onMessage(Message message, byte[] pattern) {
        super.onMessage(message, pattern);

        logger.info("修改新增redis Key:{},value:{}",message.toString(),new String(message.getBody()));
        System.out.println(new String(message.getChannel()));
    }
}
